﻿using System.Windows;
using System.Windows.Controls;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void SetTaskItemType(Expressions.BaseText.TaskType newTaskType)
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            LunarPresentation.Expressions.Expression curEx
                = Globals.selectedEditor.SelectedExpression;

            if (curEx is Expressions.BaseText == false)
            {
                MessageBox.Show("请先选中一个文本块！", Globals.appName,
                    MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            Expressions.BaseText bt = curEx as Expressions.BaseText;

            if (bt.Indent <= 0)
            {
                MessageBox.Show("要设置为任务列表项的文本块至少要有一级左缩进！", Globals.appName,
                    MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (bt.ParentPanel == null || bt.ParentPanel.BasePanel.Orientation == Orientation.Horizontal)
            {
                MessageBox.Show("必须是垂直指向的子面板中的文本块才可以设置为任务列表项！", Globals.appName,
                    MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (bt.TaskItemType != newTaskType)
            {
                ModifingItem mi = new ModifingItem();

                Action act = new Action(bt.ExID, -1, bt.GetType().Name, "TaskItemType",
                    bt.TaskItemType.ToString(), newTaskType.ToString());
                bt.TaskItemType = newTaskType;

                mi.Add(act);
                bt.Editor.Do(mi);
                bt.Editor.IsModified = true;
            }
        }
    }
}
